import os
import glob
from gooey import Gooey, GooeyParser


@Gooey(language='chinese', show_success_modal=False)
def main():
    parser = GooeyParser(description="excel字数统计")
    # 去掉, widget='DirChooser'可以直接粘贴文件夹
    parser.add_argument('--top_folder', help="请选择文件夹", widget='DirChooser')
    args = parser.parse_args()
    TOP_FOLDER = args.top_folder
    print(TOP_FOLDER)
    output_file = os.path.join(TOP_FOLDER, r'输出文件.txt')
    excel_files = [f for f in glob.glob(rf'{TOP_FOLDER}\**\*.xlsx', recursive=True) if '~$' not in f]
    with open(output_file, "w", encoding='utf-8') as fw:
        fw.writelines([f'{f}\n' for f in excel_files])
    print(f'saved to {output_file}')


if __name__ == '__main__':
    main()
